package com.zy.graph;

import java.util.LinkedList;

/**
 * @author zhaoyi
 * @date 2021/12/20 6:22 下午
 * 用邻接表方式的图
 *
 * https://leetcode-cn.com/leetbook/read/top-interview-questions-medium/xvtsnm/
 * https://leetcode-cn.com/leetbook/read/top-interview-questions-hard/xdxc56/
 */
public class Graph {

    //节点个数
    private Integer count;

    //邻接表
    private LinkedList<Integer>[] table;

    public Graph(int count) {
        this.count = count;
        table = new LinkedList[count];
        for (int i = 0; i < count; ++i) {
         table[i] = new LinkedList<>();
        }
    }


    public void addEdge(Integer s, Integer t) {
        table[s].add(t);
        //无向图添加边
        //table[t].add(s);
    }

    public LinkedList<Integer>[] getTable() {
        return table;
    }

    public Integer getCount() {
        return count;
    }
}
